package com.nulstudio.emotion.text.controller;

import com.nulstudio.emotion.text.common.NulResult;
import com.nulstudio.emotion.text.entity.NulProfile;
import com.nulstudio.emotion.text.jwt.NulJwtToken;
import com.nulstudio.emotion.text.request.LoginRequest;
import com.nulstudio.emotion.text.request.RegisterRequest;
import com.nulstudio.emotion.text.service.AccountService;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/account")
public class AccountController {

    private final AccountService accountService;

    public AccountController(@NonNull AccountService accountService) {
        this.accountService = accountService;
    }

    @PostMapping("/login")
    public NulResult<NulJwtToken> login(@RequestBody @NonNull LoginRequest request) {
        return NulResult.response(accountService.login(request.userName(), request.password()));
    }

    @PostMapping("/register")
    public NulResult<Void> register(@RequestBody @NonNull RegisterRequest request) {
        accountService.register(request.userName(), request.name(), request.password(),
                request.gender(), request.inviteCode());
        return NulResult.response();
    }

    @GetMapping("/profile")
    public NulResult<NulProfile> profile() {
        return NulResult.response(accountService.getUserProfile());
    }
}
